<template>
<div class="tab-control">
<div class="tab-control-item" v-for="(item,index) in titles" :key="index" @click="changeTab(index)">
  <span :class="{active:index==Index}">{{item}}</span>
</div>
</div>
</template>

<script>
import {ref} from 'vue'
export default {
  name: "TabControl",
  props:['titles'],
  setup(props,{emit}){
    const Index=ref(0)
    function changeTab(index){
     Index.value=index
      emit('tabClick',index)
    }
    return{
      changeTab,
      Index
    }
  }
}
</script>

<style scoped lang="less">
.tab-control{
  z-index: 999;
  background-color: white;
  display: flex;
  flex: 1;
  text-align: center;
  position: sticky;
  top:40px;
  font-size: 14px;
  line-height: 40px;
  .tab-control-item{
    flex:1;
    span{
      display: inline-block;
      width: 40px;
      height: 35px;
    }
  }
}
.active{
  color: #42b983;
  border-bottom: 5px solid #42b983;
}
</style>
